import fetch from 'utils/fetch'

// 会员中心的优教机构在user里

// 获取优教机构列表
export function getOrgList(data) {
  return fetch({
    url: '/org/list/',
    method: 'get',
    params: data
  })
}

// 获取优教机构详情
export function getOrgInfo(data) {
  return fetch({
    url: '/org/detail/',
    method: 'get',
    params: data
  })
}

// 申请入驻优教
export function registerOrg(data) {
  return fetch({
    url: '/org/regist/',
    method: 'post',
    data,
    transformRequest: [function(data) {
      // Do whatever you want to transform the data
      const form = new FormData()
      for (const key in data) {
        form.append(key, data[key])
      }
      return form
    }],
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取社群
export function getCummunity(data) {
  return fetch({
    url: '/org/list/group/',
    method: 'get',
    params: data
  })
}

// 新增机构教师
export function addOrgTeaher(data) {
  return fetch({
    url: '/org/teacher/',
    method: 'post',
    data,
    transformRequest: [function(data) {
      // Do whatever you want to transform the data
      const form = new FormData()
      for (const key in data) {
        form.append(key, data[key])
      }
      return form
    }],
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function applyAds(data) {
  return fetch({
    url: '/org/apply/ads/',
    method: 'post',
    data,
    transformRequest: [function(data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (const it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}